package com.xlh.service.courseTest;

import com.xlh.dto.courseTest.QuestionListDTO;
import com.xlh.dto.courseTest.model.ModelNotChapterDTO;
import com.xlh.enums.courseTest.QuestionBusinessTypeEnum;
import com.xlh.pojo.courseTest.CourseQuestionRepository;
import com.xlh.pojo.courseTest.CourseQuestionRepositoryDetails;
import com.xlh.pojo.courseTest.CourseQuestionRepositoryExample;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;
import java.util.Map;

/**
 * @author zhr 2019/2/11
 */
public interface QuestionRepositoryService {

    List<QuestionListDTO> questionList(String keyWord, Long courseId, Long chapterId, Integer questionType, Integer businessType, Long userId, Boolean isPreset);
    List<QuestionListDTO> questionListOther(String keyWord, Long courseId, Long chapterId, Integer questionType, Integer businessType, Long userId, Boolean isPreset);

    /**
     * @param courseId     课程id
     * @param userId       用户id
     * @param businessType 业务类型，通常为考试
     * @return 教师某课程下的全部题目
     */
    List<CourseQuestionRepository> getUserQuestionList(Long courseId, Long userId, Integer businessType);

    /**
     * 各种题型的题目数量
     */
    List<ModelNotChapterDTO> questionCount(Long courseId, Long chapterId);

    /**
     * @param questionIds 问题id
     * @return 指定id列表的全部题目
     */
    List<CourseQuestionRepository> selectQuestionByIds(List<Long> questionIds);

    /**
     * @param chapterId        章节id
     * @param businessTypeEnum 业务类型
     * @return 章节下的所有题目
     */
    List<CourseQuestionRepository> selectQuestionIdByChapterId(Long chapterId, QuestionBusinessTypeEnum businessTypeEnum);

    /**
     * @return 通过主键查询题目
     */
    CourseQuestionRepository selectByPrimaryKey(Long id);

    /**
     * 输入题目的id,返回题目所属课程id
     */
    Long getCourseId(Long id);

    /**
     * 根据课程id或者章节id删除题目
     */
    void deleteQuestion(List<Long> chapterIds);

    /**
     * 根据课程id或者章节id删除题目
     */
    void deleteQuestion(List<Long> chapterIds, QuestionBusinessTypeEnum typeEnum);


    /**
     * 将问题转义到指定用户下
     * @param chapterIds 章节信息
     * @param userId 指定给用户
     */
    void moveQuestionToSpecifyUser(List<Long> chapterIds, Long userId);



    void importQuestion(
            Long courseId, Long userId, Boolean isTeacher, Boolean isPresetCourse,
            List<CourseQuestionRepository> questionList,
            Map<Long, List<CourseQuestionRepositoryDetails>> detailsListMap
    );

    /**
     * 拷贝题库或随堂练习
     * <pre>拷贝章节时:需要将章节id都带上</pre>
     * <pre>拷贝课程时:不仅需要将每个章节的题目都拷贝,还需要调用一次chapterId与newChapterId为空时的拷贝</pre>
     */
    void copyRepository(Long courseId, Long chapterId, Long newChapterId, Long newCourseId, Long userId, Boolean isTeacher);

    /**
     * 获取章节练习布置情况
     */
    Map<Long, Boolean> getExistMap(List<Long> chapterIds);

    long countByExample(CourseQuestionRepositoryExample example);

    void insertSelective(CourseQuestionRepository repository);

    List<CourseQuestionRepository> selectByExample(CourseQuestionRepositoryExample example);

    Long selectMaxId();

    void insertBatch(List<CourseQuestionRepository> questionList);

    void updateByPrimaryKeySelective(CourseQuestionRepository question);

    void updateDeleteByIds(List<Long> questionIds);

    List<QuestionListDTO> questionListByIds(List<Long> ids);

    /**
     * 从外部服务器拷贝题目资源至本地
     * @param jdbcTemplate 保存外部链接信息
     * @param courseIdMap 待操作课程映射信息
     * @param chapterIdMap 待操作章节映射信息
     */
    void copyRepositoryOverServer(JdbcTemplate jdbcTemplate, Map<Long, Long> courseIdMap, Map<Long, Long> chapterIdMap);

    /**
     * 根据章节id集合， 返回教师端配置了随堂练习的章节id集合
     * @param chapterIds
     * @return
     */
    List<Long> findHavePracticeChapterIds(List<Long> chapterIds);


    /**
     * 更新题库信息 根据课程ID
     * @param courseQuestionRepository
     */
    void updateByCourseId(CourseQuestionRepository courseQuestionRepository, Long courseId);



}
